<template>
	<div>
		<el-form ref="form" :model="form" label-width="80px">
		    <el-form-item label="内容">
				<div>
					<div class="flex" v-for="(el,i) in form.content">
						<div class="flex" style="width: 140px;">
							<div style="margin-right: 10px;">
								标题
							</div>
							<el-input size="mini"
								style="width: 100px;"
								v-model="el.title"></el-input>
						</div>
						<!-- <div class="flex" style="width: 300px;">
							<div style="margin-right: 10px;">
								描述
							</div>
							<el-input size="mini"
								type="textarea"
								style="width:260px;margin-top: 8px;"
								v-model="el.desc"></el-input>
						</div> -->
						<div class="flex" style="margin: 0 30px;">
							<div style="width: 50px;">
								是否必填
							</div>
							<el-radio-group ref="radio" 
								style="margin-top: 12px;"
								v-model="el.isMust">
								<el-radio label="0">否</el-radio>
								<el-radio label="1">是</el-radio>
							</el-radio-group>
						</div>
						<div style="margin-left: 20px;">
							<i class="el-icon-remove-outline"
								@click="delPop(i)"
								style="font-size: 20px;margin-right: 5px;cursor: pointer;"
								></i>
							<i 
								@click="addPop"
								style="font-size: 20px;cursor: pointer;"
								class="el-icon-circle-plus-outline"></i>
						</div>
					</div>
				</div>
			</el-form-item>
			<el-form-item label="状态">
			  <el-radio-group ref="radio" v-model="form.status">
				<el-radio label="0">禁用</el-radio>
				<el-radio label="1">启用</el-radio>
			  </el-radio-group>
			</el-form-item>
			<el-form-item label="排序">
				<el-input size="mini"
					type="number"
					v-model="form.sort"></el-input>
			</el-form-item>
			<el-form-item >
			  <el-button type="primary" @click="confirm" size="small">确定</el-button>
		    </el-form-item>
		</el-form>
		
		
	</div>
</template>

<script>
	
	export default {
		components:{
		},
		props:{
			formDD:{
				type:Object,
				default:{}
			}
		},
		mounted() {
			// 获取到带有aria-hidden属性的元素
			  const ariaEls = this.$refs.radio.$el.querySelectorAll('input[type="radio"]')
			  if (!ariaEls) return
			  ariaEls.forEach((item) => {
			    // aria-hidden属性
			    item.removeAttribute('aria-hidden');
			  });
			setTimeout(()=>{
				if(this.formDD.content){
					this.form.content = JSON.parse(this.formDD.content)
				}
				this.form.status = this.formDD.status
				this.form.sort = this.formDD.sort
			},100)
		},
		data(){
			return {
				isShow:false,
				form:{
					content:[
						{
							title:'',
							value:"",
							isMust:'0',
							desc:""
						}
					],
					status:'1',
					sort:1
				}
			}
		},
		methods:{
			addPop(){
				this.form.content.push({
					title:'',
					value:"",
					isMust:'0',
					desc:""
				})
			},
			delPop(i){
				if(this.form.content.length==1) return this.$message.error('只有一个不能删除')
				this.form.content.splice(i,1)
			},
			getImgData(val){
				this.form.content.push(val)
				this.isShow = false
			},
			delImg(i){
				this.form.content.splice(i,1)
			},
			confirm(){
				let params = {
					content:JSON.stringify(this.form.content),
					status:this.form.status,
					sort:this.form.sort,
					cid:sessionStorage.getItem('cid')
				}
				this.$emit('getFormVal',params)
			},
		}
	}
</script>

<style>
	
</style>